package ks.client.gui.models;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import ks.managers.user.User;

//import sample.model.Car;

/**
 * My sample model has three columns.
 * 
 * @author GregJOverton
 *
 */
public class UserModel extends AbstractTableModel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6197136671891123577L;
	/** Elements for the model. */
	ArrayList<User> userList;
	
	public UserModel () {
		this.userList = new ArrayList<User>();
	}
	
	public int getColumnCount() {
		return 4;
	}

	public int getRowCount() {
		return userList.size();
	}

	/**
	 * Add car object.
	 * 
	 * @param c
	 * @return
	 */
	public boolean add(User u) {
		System.out.println("User " + u.getName() + " has been added to userList");
		return userList.add(u);
	}
	
	/**
	 * Remove from the model by actual Car object which is compared via equals
	 * method.
	 * 
	 * @param u
	 * @return
	 */
	
	
	
	public boolean remove(User u) {
		String name = u.getName();
		for(int index = 0; index < userList.size(); index++){
			if(userList.get(index).getName().equalsIgnoreCase(name)){
				userList.remove(index);
			}
			index++;
		}
		System.out.println("User " + u.getName() + " removed from userList");
		return true;
	}

	
	/**
	 * Remove from the model by name
	 * 
	 * @param make
	 * @return
	 */
	public boolean remove(String name) {
		for (int i = 0 ; i < userList.size(); i++) {
			User u = userList.get(i);
			if (u.getName().equalsIgnoreCase (name)) {
				return userList.remove(u);
			}
		}
		
		return false;
	}
	
	public Object getValueAt(int rowIndex, int columnIndex) {
		User u = userList.get(rowIndex);
		
		if (columnIndex == 0) {
			//Icon 
			return u.getIconName();
		} else if (columnIndex == 1) {
			//Name
			return u.getName();
		} else if (columnIndex == 2) {
			//Rating
			return u.getRating();
		} else if (columnIndex == 3) {
			//Table number
			return u.getName();
		}
		
		// no idea who you are...
		return "";
	}

}
